package com.xm.xmds1705083.web.controller;

import com.xm.xm.dto.ResultDto;
import com.xm.xm.dto.SearchDto;
import com.xm.xmds1705083.service.service.DuoduoBookingService;
import com.xm.xmds1705083.web.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 杭州新苗网络科技有限公司
 *
 * @author meihf
 * @create 2017/6/15
 * @description
 */
@Controller
@RequestMapping("/booking")
public class BookController extends BaseController{

    @Autowired
    DuoduoBookingService duoduoBookingService;

    /**
     * 我的预约车位列表
     */
    @RequestMapping("/myBooking")
    @ResponseBody
    public ResultDto selectBookingList(@RequestBody SearchDto searchDto){
        searchDto.setAppUserId(getUserId());
        return duoduoBookingService.selectBookingList(searchDto);
    }

    /**
     * 预约车位
     */
    @ResponseBody
    @RequestMapping("/toBooking")
    public ResultDto toBooking(@RequestBody SearchDto searchDto){
        searchDto.setAppUserId(getUserId());
        return duoduoBookingService.toBooking(searchDto);
    }

    /**
     * 取消预约车位
     */
    @ResponseBody
    @RequestMapping("/cancelBooking")
    public ResultDto cancelBooking(@RequestBody SearchDto searchDto){
       /* searchDto.setAppUserId(getUserId());*/
        String authorization =   getRequest().getHeader("AUTHORIZATION");
        if (authorization!=null){
            searchDto.setAppUserId(Math.abs( Long.valueOf( authorization.split("\\_")[0] ) ));
        }
        return duoduoBookingService.cancelBooking(searchDto);
    }

}
